<?php

/**
 * 分类管理
 */

namespace app\admin\controller;

use think\Request;
use app\admin\service\Order as OrderService;
use app\admin\validate\Order as OrderValidate;

class Order extends BaseController
{
    /**
     * 获取分类列表
     * @param Request $request
     * @param OrderService $OrderService
     * @param OrderValidate $validate
     * @return \think\response\Json
     */
    public function getList(Request $request, OrderService $OrderService, OrderValidate $validate)
    {
        $checkData = $request->param();
        if (!$validate->scene('search')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }

        $param['order_no'] = $request->param('order_no', null);
        $param['user_id'] = $request->param('user_id', null);
        $param['order_type'] = $request->param('order_type', null);
        $param['delivery_method'] = $request->param('delivery_method', null);
        $param['order_status'] = $request->param('order_status', null);
        $param['pay_status'] = $request->param('pay_status', null);
        $param['aftersales_status'] = $request->param('aftersales_status', null);
        $param['exceptionstatus'] = $request->param('exceptionstatus', null);
        $param['owner'] = $request->param('owner', null);
        $param['partner'] = $request->param('partner', null);

        $param['start_date'] = $request->param('start_time', null);
        $param['end_date'] = $request->param('end_time', null);

        $param['username'] = $request->param('username', null);
        $param['order_category'] = $request->param('order_category', null);
        $param['id'] = $request->param('id', null);
        $param['product_id'] = $request->param('product_id', null);
        $param['source'] = $request->param('source', null);
        $param['warehouse_id'] = $request->param('warehouse_id', null);
        $param['is_futures'] = $request->param('is_futures', null);

        $intPage = $request->param('pageIndex', 1);
        $intPageSize = $request->param('pageSize', 50);

        if ($param['user_id'] == null && !isSuperAdmin($request->operator_id)) { //普通用户
            $operatorService = new \app\admin\service\Operator();
            $userResult = $operatorService->getBelongCustomers($request->operator_id);
            if (0 == $userResult['code']) {
                if (1 == $userResult['data']['order_range']) {
                    $param['user_id'] =  $userResult['data']['customer_ids'];
                }
            } else {
                $param['user_id'] =  [0];
            }
        }


        $arrData = $OrderService->getList($param, (int)$intPage, (int)$intPageSize);
        return json($arrData);
    }

    /**
     * 创建普通订单
     * @param Request $request
     * @param OrderService $OrderService
     * @param OrderValidate $validate
     * @return \think\response\Json|void
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function save(Request $request, OrderService $service, OrderValidate $validate)
    {
        $checkData = $request->param();

        $param['delivery_method'] = $request->param('delivery_method', null);

        $scene = $param['delivery_method'] == 1 ? 'deliver_express' : 'deliver_self';

        if (!$validate->scene($scene)->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['operator_id'] = $request->operator_id;
        $param['name'] = $request->param('name', null);
        $param['order_no'] = $request->param('order_no', null);
        $param['phone'] = $request->param('phone', null);
        $param['passport'] = $request->param('passport', null);
        $param['vehicle'] = $request->param('vehicle', null);
        $param['annex'] = $request->param('annex', null);
        $param['address_id'] = $request->param('address_id', null);
        $param['billing_address_id'] = $request->param('billing_address_id', null);
        $param['prescription'] = $request->param('prescription', null);
        $param['delivery_terms'] = $request->param('delivery_terms', null);
        $param['user_id'] = $request->param('user_id', null);
        $param['list'] = $request->param('list', null);
        $param['notes'] = $request->param('notes', null);
        $param['order_remark'] = $request->param('order_remark', null);
        $param['wid'] = $request->param('wid', null);
        $param['warehouse_code'] = $request->param('warehouse_code', null);
        $param['order_remark'] = $request->param('order_remark', null);
        $param['logistics_fee'] = $request->param('logistics_fee', 0.0);
        $param['first_leg_logistics_fee'] = $request->param('first_leg_logistics_fee', 0.0);

        $param['currency'] = $request->has('currency') ? intval($request->param('currency')) : null;
        $param['signatory'] = $request->has('signatory') ? trim($request->param('signatory')) : null;
        $param['signing_date'] = $request->has('signing_date') ? trim($request->param('signing_date')) : null;
        $param['owner'] = $request->has('owner') ? intval($request->param('owner')) : null;
        $param['partner'] = $request->has('partner') ? trim($request->param('partner')) : null;
        $param['single_order_method'] = $request->has('single_order_method') ? intval($request->param('single_order_method')) : null;
        $param['id_number'] = $request->has('id_number') ? trim($request->param('id_number')) : null;
        $param['payment_deadline'] = $request->has('payment_deadline') ? trim($request->param('payment_deadline')) : null;
        $param['shipping_start_date'] = $request->has('shipping_start_date') ? trim($request->param('shipping_start_date')) : null;
        $param['shipping_end_date'] = $request->has('shipping_end_date') ? trim($request->param('shipping_end_date')) : null;
        $param['signing_date'] = $request->has('signing_date') ? trim($request->param('signing_date')) : null;
        $param['transfer_payment_info'] = $request->has('transfer_payment_info') ? trim($request->param('transfer_payment_info')) : null;
        $param['contract_type'] = $request->has('contract_type') ? trim($request->param('contract_type')) : null;
        $param['pay_terms'] = $request->has('pay_terms') ? intval($request->param('pay_terms')) : null;
        $param['advance_amount'] = $request->has('advance_amount') ? floatval($request->param('advance_amount')) : null;
        $param['source'] = $request->has('source') ? intval($request->param('source')) : 0;
        $param['is_sop'] = $request->has('is_sop') ? intval($request->param('is_sop')) : 0; // 是否拼单采购(Single Order Procurement) 0 - 否 1 - 是

        $arrData = $service->save($param);
        return json($arrData);
    }

    public function update(Request $request, OrderService $service, OrderValidate $validate)
    {
        $checkData = $request->param();

        $param['delivery_method'] = $request->param('delivery_method', null);

        $scene = $param['delivery_method'] == 1 ? 'deliver_express' : 'deliver_self';
        if (!$validate->scene($scene)->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['operator_id'] = $request->operator_id;
        $param['id'] = $request->param('id', null);
        $param['name'] = $request->param('name', null);
        $param['order_no'] = $request->param('order_no', null);
        $param['phone'] = $request->param('phone', null);
        $param['passport'] = $request->param('passport', null);
        $param['vehicle'] = $request->param('vehicle', null);
        $param['annex'] = $request->param('annex', null);
        $param['warehouse_code'] = $request->param('warehouse_code', null);
        $param['address_id'] = $request->param('address_id', null);
        $param['billing_address_id'] = $request->param('billing_address_id', null);
        $param['prescription'] = $request->param('prescription', null);
        $param['delivery_terms'] = $request->param('delivery_terms', null);
        $param['user_id'] = $request->param('user_id', null);
        $param['list'] = $request->param('list', null);
        $param['wid'] = $request->param('wid', null);
        $param['order_remark'] = $request->param('order_remark', null);
        $param['logistics_fee'] = $request->param('logistics_fee', 0.0);
        $param['first_leg_logistics_fee'] = $request->param('first_leg_logistics_fee', 0.0);
        $param['notes'] = $request->param('notes', null);
        $param['order_remark'] = $request->param('order_remark', null);
        $param['currency'] = $request->has('currency') ? intval($request->param('currency')) : null;
        $param['signatory'] = $request->has('signatory') ? trim($request->param('signatory')) : null;
        $param['signing_date'] = $request->has('signing_date') ? trim($request->param('signing_date')) : null;
        $param['owner'] = $request->has('owner') ? intval($request->param('owner')) : null;
        $param['partner'] = $request->has('partner') ? trim($request->param('partner')) : null;
        $param['single_order_method'] = $request->has('single_order_method') ? intval($request->param('single_order_method')) : null;
        $param['id_number'] = $request->has('id_number') ? trim($request->param('id_number')) : null;
        $param['payment_deadline'] = $request->has('payment_deadline') ? trim($request->param('payment_deadline')) : null;
        $param['shipping_start_date'] = $request->has('shipping_start_date') ? trim($request->param('shipping_start_date')) : null;
        $param['shipping_end_date'] = $request->has('shipping_end_date') ? trim($request->param('shipping_end_date')) : null;
        $param['signing_date'] = $request->has('signing_date') ? trim($request->param('signing_date')) : null;
        $param['transfer_payment_info'] = $request->has('transfer_payment_info') ? trim($request->param('transfer_payment_info')) : null;
        $param['contract_type'] = $request->has('contract_type') ? trim($request->param('contract_type')) : null;

        $param['pay_terms'] = $request->has('pay_terms') ? intval($request->param('pay_terms')) : null;
        $param['advance_amount'] = $request->has('advance_amount') ? floatval($request->param('advance_amount')) : null;
        $param['source'] = $request->has('source') ? intval($request->param('source')) : 0;
        $param['is_sop'] = $request->has('is_sop') ? intval($request->param('is_sop')) : 0; // 是否拼单采购(Single Order Procurement) 0 - 否 1 - 是

        $arrData = $service->update($param);
        return json($arrData);
    }

    /**
     * 获取单条数据
     * @param Request $request
     * @param OrderService $OrderService
     * @param OrderValidate $validate
     * @return \think\response\Json
     * 2024-12-11 14 18 34
     * author: jiang
     */
    public function getInfo(Request $request, OrderService $OrderService, OrderValidate $validate)
    {
        $checkData = $request->param();

        if (!$validate->scene('show')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['id'] = $request->param('id', null);
        $arrData = $OrderService->getInfo($param);
        return json($arrData);
    }

    /**
     * 撤销编辑
     * @param Request $request
     * @param OrderService $OrderService
     * @param OrderValidate $validate
     * @return \think\response\Json
     * 2024-12-11 14 18 34
     * author: jiang
     */
    public function cancelUpdate(Request $request, OrderService $OrderService, OrderValidate $validate)
    {
        $checkData = $request->param();

        if (!$validate->scene('show')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['id'] = $request->param('id', null);
        $param['operator_id'] = $request->operator_id;
        $arrData = $OrderService->cancelUpdate($param);
        return json($arrData);
    }
    /**
     * 订单复制
     * @param Request $request
     * @param OrderService $OrderService
     * @param OrderValidate $validate
     * @return \think\response\Json
     * 2024-12-11 14 18 34
     * author: jiang
     */
    public function copy(Request $request, OrderService $OrderService, OrderValidate $validate)
    {
        $checkData = $request->param();

        if (!$validate->scene('show')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['id'] = $request->param('id', null);
        $arrData = $OrderService->copy($param);
        return json($arrData);
    }


    /**
     * 删除单条或多条数据
     * @param Request $request
     * @param OrderValidate $validate
     * @param OrderService $OrderService
     * @return \think\response\Json
     */
    public function delete(Request $request, OrderValidate $validate, OrderService $OrderService)
    {
        $checkData = $request->param();
        if (!$validate->scene('delete')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['ids'] = $request->param('ids', null);
        $arrData = $OrderService->delete($param);
        return json($arrData);
    }
    /**
     * 删除单条或多条数据
     * @param Request $request
     * @param OrderValidate $validate
     * @param OrderService $OrderService
     * @return \think\response\Json
     */
    public function del(Request $request, OrderValidate $validate, OrderService $OrderService)
    {
        $checkData = $request->param();
        if (!$validate->scene('delete')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['ids'] = $request->param('ids', null);
        $arrData = $OrderService->del($param);
        return json($arrData);
    }

    /**
     * 下拉框获取分类信息
     * @param Request $request
     * @param OrderService $OrderService
     * @param OrderValidate $validate
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getSelect(Request $request, OrderService $OrderService, OrderValidate $validate)
    {
        $checkData = $request->param();
        if (!$validate->scene('search')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }

        $arrData = $OrderService->getSelect();
        return json($arrData);
    }

    /**
     * 订单审核
     * @param Request $request
     * @param OrderService $service
     * @param OrderValidate $validate
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * 2024-11-21 13 53 29
     * author: jiang
     */
    public function examine(Request $request, OrderService $service, OrderValidate $validate)
    {
        $checkData = $request->param();
        if (!$validate->scene('examine')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['id'] = $request->param('id', null);
        $param['is_approved'] = $request->param('is_approved', true);
        $param['operator_id'] = $request->operator_id;
        $arrData = $service->examine($param);
        return json($arrData);
    }

    /**
     * 订单发货
     * @param Request $request
     * @param OrderService $service
     * @param OrderValidate $validate
     * @return \think\response\Json
     * @throws \app\api\exception\ParameterException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * 2024-11-22 16 15 23
     * author: jiang
     */
    public function delivery(Request $request, OrderService $service, OrderValidate $validate)
    {
        $checkData = $request->param();
        if (!$validate->scene('delivery')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['order_id'] = $request->param('order_id', null);
        $param['logistics_company'] = $request->param('logistics_company', null);
        $param['wid'] = $request->param('wid', null);
        $param['list'] = $request->param('list', null);
        $param['logistics_no'] = $request->param('logistics_no', null);
        $param['logistics_voucher'] = $request->param('logistics_voucher', null);
        $param['notes'] = $request->param('notes', null);
        $param['transaction_currency_id'] = $request->param('transaction_currency_id', null);
        $param['cost'] = $request->param('cost', null);
        $param['logistics_fee'] = $request->param('logistics_fee', 0.0);
        $param['shop_fl_warehouse'] = $request->param('shop_fl_warehouse', 0);
        $param['shippinAddress'] = $request->param('shippinAddress', null);
        $param['ship_date'] = $request->param('ship_date', null);
        $param['is_part_delivery'] = $request->param('is_part_delivery', false);

        $param['operator_id'] = $request->operator_id;
        $arrData = $service->delivery($param);
        return json($arrData);
    }
    #取消发货
    public function cancelDelivery(Request $request, OrderService $service, OrderValidate $validate)
    {
        $checkData = $request->param();
        if (!$validate->scene('examine')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['id'] = $request->param('id', null);
        $param['operator_id'] = $request->operator_id;
        $arrData = $service->cancelDelivery($param);
        return json($arrData);
    }

    /**
     * 订单收货
     * @param Request $request
     * @param OrderService $service
     * @param OrderValidate $validate
     * @return \think\response\Json
     * 2024-11-22 16 15 33
     * author: jiang
     */
    public function receipt(Request $request, OrderService $service, OrderValidate $validate)
    {
        $checkData = $request->param();
        if (!$validate->scene('receipt')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['order_id'] = $request->param('order_id', null);
        $param['voucher'] = $request->param('voucher', []);
        $param['operator_id'] = $request->operator_id;
        $arrData = $service->receipt($param);
        return json($arrData);
    }

    /**
     * 订单库存枚举
     * @param Request $request
     * @param OrderValidate $validate
     * @param OrderService $service
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * 2024-12-18 16 32 56
     * author: jiang
     */
    public function transEnum(Request $request, OrderValidate $validate, OrderService $service)
    {
        // $checkData = $request->param();
        // if (!$validate->scene('transEnum')->check($checkData)) {
        //     return json(['code' => 1, 'message' => $validate->getError()]);
        // }
        $param['operator_id'] = $request->operator_id;
        $param['id'] = $request->param('id', null);
        $arrData = $service->transEnum($param);
        return json($arrData);
    }

    /**
     * 获取库存列表
     * @param Request $request
     * @param OrderValidate $validate
     * @param OrderService $service
     * @return \think\response\Json
     * 2024-12-18 16 33 14
     * author: jiang
     */
    public function getInventory(Request $request, OrderValidate $validate, OrderService $service)
    {
        $checkData = $request->param();
        if (!$validate->scene('getInventory')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['operator_id'] = $request->operator_id;
        $param['productid'] = $request->param('productid', null);
        $param['fl_warehouse_id'] = $request->param('fl_warehouse_id', null);
        $param['wid'] = $request->param('wid', null);
        $param['arrival_date'] = $request->param('arrival_date', null);
        $param['is_futures'] = $request->param('is_futures', null);
        $arrData = $service->getInventory($param);
        return json($arrData);
    }

    public function getFieldEnum(Request $request, OrderService $OrderService)
    {
        $param = $request->param('field', 'ALL');
        $arrData = $OrderService->getFieldEnum($param);
        return json($arrData);
    }

    public function confirm(Request $request, OrderService $service, OrderValidate $validate)
    {
        // $checkData = $request->param();
        // if (!$validate->scene('confirm')->check($checkData)) {
        //     return json(['code' => 1, 'message' => $validate->getError()]);
        // }
        $param['operator_id'] = $request->operator_id;
        $param['id'] = $request->param('id', null);
        $arrData = $service->confirm($param);
        return json($arrData);
    }

    public function remark(Request $request, OrderService $service, OrderValidate $validate)
    {
        // $checkData = $request->param();
        // if (!$validate->scene('confirm')->check($checkData)) {
        //     return json(['code' => 1, 'message' => $validate->getError()]);
        // }
        $param['operator_id'] = $request->operator_id;
        $param['id'] = $request->param('id', null);
        $param['order_remark'] = $request->param('order_remark', null);
        $arrData = $service->remark($param);
        return json($arrData);
    }
    public function getInventoryByAbbr(Request $request, OrderService $service, OrderValidate $validate)
    {

        $param['id'] = $request->param('id', null);
        $arrData = $service->getInventoryByAbbr($param['id']);
        return json($arrData);
    }

    public function changeWarehouse(Request $request, OrderService $service, OrderValidate $validate)
    {

        $param['iterm_id'] = $request->param('iterm_id', null);
        $param['inventory_id'] = $request->param('inventory_id', null);
        $param['operator_id'] = $request->operator_id;
        $arrData = $service->changeWarehouse($param);
        return json($arrData);
    }
    /**
     *  选项仓库商品
     */
    public function selectWarehouseProducts(Request $request, OrderService $service, OrderValidate $validate)
    {

        $checkData = $request->param();
        if (!$validate->scene('selectWarehouseProducts')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }

        $param['operator_id'] = $request->operator_id;
        $param['id'] = $request->param('id', null);
        $arrData = $service->selectWarehouseProducts($param);

        return json($arrData);
    }

    /**
     * @describe
     * @author: Bobo
     * @date: 2025-03-04 19:09:43
     * @param [type] @required
     * @return Renderable
     */
    public function getApprovalRecords(Request $request, OrderService $service, OrderValidate $validate)
    {
        $params = $request->param();
        if (!$validate->scene('getApprovalRecords')->check($params)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $pageIndex         = isset($params['pageIndex'])             ? intval($params['pageIndex'])             : 1;
        $pageSize          = isset($params['pageSize'])              ? intval($params['pageSize'])              : 100;
        $orderId           = isset($params['order_id'])              ? intval($params['order_id'])              : 0;
        $orderType         = isset($params['order_type'])            ? trim($params['order_type'])              : '';

        $arrData = $service->getApprovalRecords($pageIndex, $pageSize,  $orderType, $orderId, $field = 'id,user_id,operate,user_type,content,create_time');

        return json($arrData);
    }

    /**
     * 获取操作记录
     * @describe
     * @author: Assistant
     * @date: 2025-01-27 10:00:00
     * @param Request $request
     * @param OrderService $service
     * @param OrderValidate $validate
     * @return \think\response\Json
     */
    public function getOperationRecords(Request $request, OrderService $service, OrderValidate $validate)
    {
        $params = $request->param();
        if (!$validate->scene('getOperationRecords')->check($params)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $pageIndex         = isset($params['pageIndex'])             ? intval($params['pageIndex'])             : 1;
        $pageSize          = isset($params['pageSize'])              ? intval($params['pageSize'])              : 100;
        $orderId           = isset($params['order_id'])              ? intval($params['order_id'])              : 0;
        $orderType         = isset($params['order_type'])            ? trim($params['order_type'])              : '';

        $arrData = $service->getOperationRecords($pageIndex, $pageSize, $orderType, $orderId, $field = 'id,user_id,operate,user_type,content,create_time');

        return json($arrData);
    }

    /**
     * @describe
     * @author: Bobo
     * @date: 2025-03-05 14:05:14
     * @param [type] @required
     * @return Renderable
     */
    public function contractPreview(Request $request, OrderService $service, OrderValidate $validate)
    {
        $checkData = $request->param();
        if (!$validate->scene('contractPreview')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $orderId = $request->param('order_id', 0);
        $arrData = $service->contractPreview($orderId, 1, $request->operator_id);
        return json($arrData);
    }

    /**
     * @describe
     * @author: Bobo
     * @date: 2025-03-06 19:13:49
     * @param [type] @required
     * @return Renderable
     */
    public function getAsociatedPurchaseOrders(Request $request, OrderService $service, OrderValidate $validate)
    {
        $checkData = $request->param();
        if (!$validate->scene('getApprovalRecords')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $orderId = $request->param('order_id', 0);
        $orderType = $request->param('order_type', '');
        $arrData = $service->getAsociatedPurchaseOrders($orderId, $orderType, $request->operator_id);
        return json($arrData);
    }

    /**
     * 取消订单
     * @param Request $request
     * @param OrderService $service
     * @param OrderValidate $validate
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * 2025-03-11 15 00 06
     * author: jiang
     */
    public function cancel(Request $request, OrderService $service, OrderValidate $validate)
    {
        $checkData = $request->param();
        if (!$validate->scene('cancel')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['id'] = $request->param('id', null);
        $param['operator_id'] = $request->operator_id;
        $arrData = $service->cancel($param);
        return json($arrData);
    }

    /**
     * @describe 锁定库存 用于锁定支付成功之后锁定库存的订单
     * @author: Bobo
     * @date: 2025-06-05 15:37:48
     * @param [type] @required
     * @return Renderable
     */
    public function lockInventory(Request $request, OrderService $service, OrderValidate $validate)
    {
        $checkData = $request->param();
        if (!$validate->scene('lockInventory')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['id'] = $request->param('id', null);
        $param['operator_id'] = $request->operator_id;
        $arrData = $service->lockInventory($param);
        return json($arrData);
    }
    /**
     * @describe 校对异常订单商品明细
     * @author: Bobo
     * @date: 2025-08-11 18:30:26
     * @param [type] @required
     * @return Renderable
     */
    public function checkExceptionOrderItem(Request $request, OrderService $service, OrderValidate $validate)
    {
        $checkData = $request->param();
        if (!$validate->scene('checkExceptionOrderItem')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['id'] = $request->param('id', null);
        $param['product_list'] = $request->param('product_list', null);
        $param['operator_id'] = $request->operator_id;
        $arrData = $service->checkExceptionOrderItem($param);
        return json($arrData);
    }

    /**
     * @describe 订单无需发货
     * @author: Bobo
     * @date: 2025-08-14 19:17:05
     * @param [type] @required
     * @return Renderable
     */
    public function noDelivery(Request $request, OrderService $service, OrderValidate $validate)
    {
        $checkData = $request->param();
        if (!$validate->scene('noDelivery')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['id'] = $request->param('id', null);
        $param['order_item_id'] = $request->param('order_item_id', null);
        $param['operator_id'] = $request->operator_id;
        $arrData = $service->noDelivery($param);
        return json($arrData);
    }


    public function getReviewInfo(Request $request, OrderService $service, OrderValidate $validate)
    {
        $checkData = $request->param();
        if (!$validate->scene('show')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $id = $request->param('id', null);
        $arrData = $service->getReviewInfo($id);
        return json($arrData);
    }

    /**
     * @describe 获取库存转换信息
     * @author: Bobo
     * @date: 2025-08-26 17:58:00
     * @param [type] @required
     * @return Renderable
     */
    public function getInventoryTransSaveInfo(Request $request, OrderService $service, OrderValidate $validate)
    {

        $checkData = $request->param();

        if (!$validate->scene('inventory_trans_save_info')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $orderId = intval($request->param('order_id', 0));
        $orderItemId = intval($request->param('order_item_id', 0));
        $wholesalId = intval($request->param('wholesal_id', 0));

        $arrData = $service->getInventoryTransSaveInfo($orderId, $orderItemId, $wholesalId);
        return json($arrData);
    }
}
